* Code for "Inequality and the environmental Kuznets curve" 
* Journal of Cleaner Production
* DOI: https://doi.org/10.1016/j.jclepro.2019.04.284
* by Sulhi Ridzuan

* Table 1

sum sulfurpc sulfurprgdp rgdppc giniswiid giniwb giniwyd urban trade

* Table 2

xtscc lnsulfurpc ygt gt gtginiswiidavg t, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]
qui xtreg lnsulfurpc ygt gt gtginiswiidavg t, re
xtoverid

xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]
qui xtreg lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, re
xtoverid

* Table 3

xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]
qui xtreg lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, re
xtoverid

reg lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t i.id
predict dfits if e(sample), dfits

gen cutoffdfit= abs(dfits)>2*sqrt((e(df_m)+1)/e(N)) & e(sample)
xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t if cutoffdfit==0, fe

nlcom - _b[gtginiswiidavg]/_b[ygt]
drop cutoffdfit dfits

xtqreg lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, i(id)
nlcom - _b[gtginiswiidavg]/_b[ygt]

* Table 4

xtscc lnsulfurpc ygt gt gtginiwbavg lnurban lntrade t, fe
nlcom - _b[gtginiwbavg]/_b[ygt]

xtscc lnsulfurpc ygt gt gtginiwydavg lnurban lntrade t, fe
nlcom - _b[gtginiwydavg]/_b[ygt]

xtscc lnsulfurprgdp ygt gt gtginiswiidavg lnurban lntrade t, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]

xtscc lnsulfurprgdp ygt gt gtginiwbavg lnurban lntrade t, fe
nlcom - _b[gtginiwbavg]/_b[ygt]

xtscc lnsulfurprgdp ygt gt gtginiwydavg lnurban lntrade t, fe
nlcom - _b[gtginiwydavg]/_b[ygt]

* Table 5

xtscc lnsulfurpc lnrgdppc lnrgdppc2 lnrgdppc_giniswiidavg lnurban lntrade t, fe

xtscc lnsulfurpc lnrgdppc lnrgdppc2 lnrgdppc_giniwbavg lnurban lntrade t, fe

xtscc lnsulfurpc lnrgdppc lnrgdppc2 lnrgdppc_giniwydavg lnurban lntrade t, fe

* Table 6

xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t if highinc==1, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]

xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t if highinc==0, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]

xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, re
nlcom - _b[gtginiswiidavg]/_b[ygt]

encode region, gen(dregion)
xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t i.dregion, re
nlcom - _b[gtginiswiidavg]/_b[ygt]
drop dregion

preserve
keep id year lnsulfurpc rgdppc giniswiid lnurban lntrade
bys id (year): egen y1 = mean(rgdppc) if inrange(year,1991,1994)
bys id (year): egen y2 = mean(rgdppc) if inrange(year,1997,2000)
bys id (year): egen y1_ = mean(y1)
bys id (year): egen y2_ = mean(y2)
gen g = (log(y2_/y1_))/6
gen y = y1_ * exp(3*g)
gen t = year - 1990
gen ygt = y*g*t
gen gt = g*t
sort id year
bys id (year): egen giniswiidavg = mean(giniswiid) if inrange(year,1991,2000)
gen gtginiswiidavg = gt *giniswiidavg
tsset id t
xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t, fe
nlcom - _b[gtginiswiidavg]/_b[ygt]
restore

preserve
keep id year lnsulfurpc rgdppc giniswiid lnurban lntrade
bys id (year): egen y1 = mean(rgdppc) if inrange(year,2001,2004)
bys id (year): egen y2 = mean(rgdppc) if inrange(year,2007,2010)
bys id (year): egen y1_ = mean(y1)
bys id (year): egen y2_ = mean(y2)
gen g = (log(y2_/y1_))/6
gen y = y1_ * exp(3*g)
gen t = year - 2000
gen ygt = y*g*t
gen gt = g*t
sort id year
bys id (year): egen giniswiidavg = mean(giniswiid) if inrange(year,2000,2010)
gen gtginiswiidavg = gt *giniswiidavg
tsset id t
drop if t<1
xtscc lnsulfurpc ygt gt gtginiswiidavg lnurban lntrade t if inrange(year,2000,2010), fe
nlcom - _b[gtginiswiidavg]/_b[ygt]
restore
